
//subjectList点击
var subjectListEvent=function(){
    $(".subjectList").unbind('click').click(function(){
        var statusArr={
            'auth_token':tokens,
            'group_id':$(this).attr('data-id'),
            'group_type':1,
            'mode':2,
            'history_id':0
        };
        $.cookie('statusArr',JSON.stringify(statusArr));
        $.cookie('statusArrBool',false);
    });
};


//请求课程分类列表数据
var topicList=function(arr,qctp){
    $.ajax({
        type: "GET",
        url:base_url + qctp,
        data:arr,
        beforeSend:function(XMLHttpRequest){},
        success:function(data){
            var datas=data.data;
            if(datas){
                var page_contents=datas.page_contents;
                for(var i=0;i<page_contents.length;i++){
                    var group_desc=page_contents[i].group_desc;
                    var group_id=page_contents[i].group_id;
                    var group_type=page_contents[i].group_type||arr['qctpName'];

                    var li='<div class="subjectList" data-id="'+group_id+'">\n' +
                        '          <a href="overyears/list.html">\n' +
                        '                    <div class="subjectHover">\n' +
                        '                        <div class="subjectEditorBut"></div>\n' +
                        '                        <h2>'+group_desc+'</h2>\n' +
                        '                        <h2 class="on">'+group_type+'</h2>\n' +
                        // '                        <div class="subjectGrade"><i></i><span>难度等级</span></div>\n' +
                        '                        <div class="subjectStar">\n' +
                        '                            <ul>\n' +
                        '                                <li></li>\n' +
                        '                                <li></li>\n' +
                        '                                <li></li>\n' +
                        '                                <li></li>\n' +
                        '                                <li></li>\n' +
                        '                            </ul>\n' +
                        '                        </div>\n' +
                        '                        <div class="subjectToggle">\n' +
                        '                            <button>开始做题</button>\n' +
                        '                        </div>\n' +
                        '                    </div>\n' +
                        '                    </a>\n' +
                        '                </div>';
                    $(".mainRight").append(li);
                }
                subjectListEvent();
            }
        },
        error:function(){
            console.log('失败')
        }

    });
};
$(function(){
    //判断token
    if(tokens){
        var qctpBool=$.cookie('qctpBool');
        if(qctpBool){
            qctpBool=JSON.parse($.cookie('qctpBool'));
            if(!isEmptyObject(qctpBool)){
                var qctpType=qctpBool.qctpType;
                var qctpId=qctpBool.id;
                var qctpName=qctpBool.qctpName;
                var arr1;
                switch (qctpType) {
                    case 'kp':
                        arr1={
                            'auth_token':tokens,
                            'sc_id':qctpId,
                            'page_no':1,
                            'page_size':18,
                            'qctpName':qctpName
                        };
                        topicList(arr1,'kp/list');
                        break;
                    case 'tp':
                        arr1={
                            'auth_token':tokens,
                            'page_no':1,
                            'page_size':18
                        };
                        topicList(arr1,'tp/list');
                        break;
                    case 'qt':
                        arr1={
                            'auth_token':tokens,
                            'category_id':qctpId,
                            'page_no':1,
                            'page_size':18,
                            'qctpName':qctpName
                        };
                        topicList(arr1,'qt/list');
                        break
                }
            }
        }
    }else{
        layTxt('您还没登录!');
        setTimeout(function(){
            setUrl('overyears','login')//设置跳转
        },1000)
    }

    //星级悬停效果
    $(".subjectStar ul li").hover(function(){
        var indexs=($(this).index())+1;
        for(var i=0; i<indexs;i++){
            $(this).parents('.subjectStar').find("ul li").eq(i).addClass('on')
        }
    },function(){
        var parentObj=$(this).parents('.subjectStar');
        var ObjSpot=parentObj.attr('data-index');
        parentObj.find("ul li").removeClass('on');
        for(var i=0; i<ObjSpot;i++){
            parentObj.find("ul li").eq(i).addClass('on')
        }
    });
});

//echarts
var echartData={
    "dataX":['0', '1', '2', '3', '4', '5', '6'],
    "dataY":[820, 932, 901, 934, 1290, 1330, 1320]
};
echartEvent(echartData);